package com.ncloud.resman.mapper;

import com.ncloud.resman.entity.VirtualDisk;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * Created by shiqiang on 2017/8/14.
 */
@Mapper
public interface VirtualDiskMapper {
    @Insert("insert into res_virtual_disk(disk_id, virtual_id, disk_capacity, host_ip, state, create_user, create_date, update_user, update_date)"
            + " values(#{diskId},#{virtualId},#{diskCapacity},#{hostIp},#{state},#{createUser},#{createDate},#{updateUser},#{updateDate})")
    int insertVirtualDisk(VirtualDisk virtualDisk);
    @Update("update res_virtual_disk set host_ip = #{hostIp},disk_capacity=#{diskCapacity}," +
            " update_user=#{updateUser},update_date=#{updateDate} where state='1' and disk_id =#{diskId}")
    int updateVirtualDisk(VirtualDisk virtualDisk);

    @Select("SELECT disk_id, virtual_id, disk_capacity, host_ip, state "
            + "FROM res_virtual_disk where disk_id = #{diskId} and state='1'")
    @Results({
            @Result(column="disk_id",property="diskId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="disk_capacity",property="diskCapacity"),@Result(column="host_ip",property="hostIp"),
            @Result(column="state",property="state")})
    VirtualDisk getVirtualDiskById(Long diskId);//
    /*获取虚拟机硬盘信息*/
    @Select("SELECT disk_id, virtual_id, disk_capacity, host_ip, state "
            + "FROM res_virtual_disk where virtual_id = #{virtualId} and state='1'")
    @Results({
            @Result(column="disk_id",property="diskId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="disk_capacity",property="diskCapacity"),@Result(column="host_ip",property="hostIp"),
            @Result(column="state",property="state")})
    List<VirtualDisk> getVirtualDiskByVirtualId(Long virtualId);//

    /*根据hostIp,获取虚拟机硬盘信息*/
    @Select("SELECT disk_id, virtual_id, disk_capacity, host_ip, state "
            + "FROM res_virtual_disk where host_ip = #{0} and state='1'")
    @Results({
            @Result(column="disk_id",property="diskId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="disk_capacity",property="diskCapacity"),@Result(column="host_ip",property="hostIp"),
            @Result(column="state",property="state")})
    List<VirtualDisk> getVirtualDiskByHostIp(String hostIp);//
    /*删除*/
    @Delete(value = "delete from res_virtual_disk WHERE disk_id = #{0}")
    int deleteVirtualDisk(Long diskId);

    /*删除*/
    @Delete(value = "delete from res_virtual_disk WHERE virtual_id = #{0}")
    int deleteVirtualDiskByVirtualId(Long virtualId);
    @Update("update res_virtual_disk set state= #{1} " +
            " where state='1' and disk_id =#{0}")
    int updateVirtualDiskState(Long diskId,String state);


}
